package com.cloudcc.mobile.weight;

import android.content.Context;
import android.content.res.TypedArray;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.cloudcc.mobile.R;

/**
 * Created by lin on 2017/7/14.
 */

public class WeakPromptToast extends RelativeLayout implements View.OnClickListener {

    private TextView textView;
    private ImageView imageView;

    public WeakPromptToast(Context context) {
        super(context);
    }

    public WeakPromptToast(Context context, AttributeSet attrs) {
        super(context, attrs);
        LayoutInflater.from(context).inflate(R.layout.a_toast_showhint, this, true);


        textView = (TextView) findViewById(R.id.toastHintContent);
        imageView = (ImageView) findViewById(R.id.imgDeletes);

        TypedArray attributes = context.obtainStyledAttributes(attrs, R.styleable.ImageBtnWithText);

        if (attributes != null) {

            int allbg = attributes.getResourceId(R.styleable.ImageBtnWithText_all_background, R.drawable.toast_hint_beau);
            setBackgroundResource(allbg);
            //设置左边按钮的文字
            String leftButtonText = attributes.getString(R.styleable.ImageBtnWithText_toast_text);
            textView.setText(leftButtonText);

            imageView.setOnClickListener(this);
        }
    }

    /**
     * 设置显示的文字
     * @param textTitle
     */
    public void setTextTitle(String textTitle){
        textView.setText(textTitle);
    }

    /**
     * 代码设置背景
     * @param bg
     */
    public void setAllBg(int bg){
        setBackgroundResource(bg);
    }

    @Override
    public void onClick(View v) {
        this.setVisibility(View.GONE);
    }
}
